<template>
  <a-card>
    <!-- 查询区域 -->
    <div :class="{ search: advanced }">
      <a-form layout="horizontal" :labelCol="{ span: 8 }" :wrapperCol="{ span: 15 }">
        <div :class="{ fold: !advanced }">
          <a-row>
            <a-col :md="6" :sm="24">
              <a-form-item label="考核日期">
                <a-range-picker v-model="searchForm.range" separator="至" />
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="24">
              <a-form-item label="考核类别">
                <a-select allowClear v-model="searchForm.inspectionType" placeholder="考核类别">
                  <a-select-option
                    v-for="type in inspectionTypeOptions"
                    :value="type.value"
                    :key="type.id"
                  >
                    {{ type.value }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="24">
              <a-form-item label="考核部门">
                <a-select
                  allowClear
                  v-model="searchForm.executeDept"
                  placeholder="考核部门"
                  @change="handleSearchFormExecuteDeptChange"
                >
                  <a-select-option :value="dept.id" v-for="dept in allDept" :key="dept.id">{{
                    dept.deptName
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="24">
              <a-form-item label="考核条例">
                <a-select
                  :allowClear="true"
                  v-model="searchForm.regulationNo"
                  placeholder="考核条例"
                >
                  <a-select-option
                    :value="regulation.id"
                    v-for="regulation in searchForm.regulationList"
                    :key="regulation.id"
                  >
                    {{ regulation.regulationName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>

          <a-row v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-item label="被考核支部">
                <a-select
                  allowClear
                  v-model="searchForm.inspectBranch"
                  placeholder="被考核支部"
                  @change="handleSearch"
                >
                  <a-select-option v-for="item in allBranch" :value="item.id" :key="item.id">
                    {{ item.branchName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="事件内容">
                <a-input
                  v-model="searchForm.eventContent"
                  :allowClear="true"
                  placeholder="事件内容"
                  @keyup.enter="handleSearch"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="考核分">
                <a-input
                  type="number"
                  v-model="searchForm.inspectScore"
                  :allowClear="true"
                  placeholder="考核分"
                  @keyup.enter="handleSearch"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="是否整改">
                <a-radio-group v-model="searchForm.isCorrect" style="width: 100%;">
                  <a-radio :value="null">全部</a-radio>
                  <a-radio :value="1">是</a-radio>
                  <a-radio :value="0">否</a-radio>
                </a-radio-group>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
        <span style="float: right; margin-top: 3px;">
          <a-button v-permission="`inspection:event:list`" type="primary" @click="handleSearch"
            >查询</a-button
          >
          <a-button class="ml-8" @click="handleReset">重置</a-button>

          <a @click="advanced = !advanced" class="ml-8">
            {{ advanced ? '收起' : '展开' }}
            <a-icon :type="advanced ? 'up' : 'down'" />
          </a>
        </span>
      </a-form>
    </div>

    <!-- 表格区域 -->
    <div>
      <div class="operator">
        <a-button
          v-permission="`inspection:event:add`"
          class="mr-8"
          type="primary"
          @click="handleAddEvent"
          >新增</a-button
        >
        <a-button
          v-permission="`inspection:event:export`"
          class="mr-8 btn-success"
          type="primary"
          @click="handleExport"
          >数据导出</a-button
        >
        <a-button
          v-permission="`inspection:event:delbatch`"
          :class="{ 'btn-disabled': !rowSelection.selectedRowKeys.length }"
          type="danger"
          @click="handleDelAll"
          >批量删除</a-button
        >
      </div>

      <div style="margin:16px 0;">
        <a-popover
          placement="bottom"
          overlayClassName="columns-select"
          title="列选择"
          :arrowPointAtCenter="true"
          trigger="click"
        >
          <a-icon class="icon-table" type="table" />
          <template slot="content">
            <a-checkbox-group
              class="check-group"
              v-model="colList"
              name="checkboxgroup"
              :options="columnsOptions"
              @change="handleColChange"
            />
          </template>
        </a-popover>
      </div>

      <a-table
        class="table"
        bordered
        :scroll="{ x: 2000 }"
        :loading="loading"
        :columns="columns"
        :pagination="pagination"
        :data-source="dataSource"
        :row-key="item => item.id"
        :row-selection="rowSelection"
        :customRow="customRow"
        @change="handleTableChange"
      >
        <div slot="eventContent" slot-scope="text" class="ellipsis" :title="text">{{text}}</div>
        <div slot="regulationContent" slot-scope="text" class="ellipsis" :title="text">{{text}}</div>

        <span slot="status" slot-scope="item">
          <a-tag v-if="item === 1" color="green">是</a-tag>
          <a-tag v-if="item === 0" color="red">否</a-tag>
        </span>

        <span slot="approveStatus" slot-scope="item">
          <a-tag v-if="item === 1" color="green">是</a-tag>
          <a-tag v-if="item === 0" color="red">否</a-tag>
        </span>

        <span slot="action" slot-scope="item">
          <template v-if="item.approveStatus === 0">
            <a-popconfirm
              title="确认通过审核吗？"
              ok-text="确认"
              cancel-text="取消"
              @confirm="handleApprove(item)"
            >
              <a v-permission="`inspection:event:approve`" style="color:green;" href="#">审批</a>
            </a-popconfirm>
            <a-divider type="vertical" />
            <a v-permission="`inspection:event:update`" href="#" @click="handleEdit(item)">编辑</a>
          </template>

          <template v-else>
            <a v-permission="`inspection:event:rectify`" href="#" @click="rectification(item)">
              整改
            </a>
          </template>

          <a-divider type="vertical" />

          <a-popconfirm
            title="确认是否删除"
            ok-text="确认"
            cancel-text="取消"
            @confirm="handleDelete(item)"
          >
            <a v-permission="`inspection:event:del`" href="#" style="color: red">删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <!-- 新增弹窗 -->
    <a-modal
      width="900px"
      :title="type == 1 ? '新增' : '修改'"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <a-form class="inline-form" v-bind="formItemLayout" :form="form" layout="inline">
        <a-form-item label="考核部门">
          <a-select
            v-decorator="['executeDept', { rules: [{ required: true, message: '请选择' }] }]"
            placeholder="请选择考核部门"
            @change="handleExecuteDeptChange"
            :disabled="type == 2 || type === 3"
          >
            <a-select-option :value="dept.id" v-for="dept in allDept" :key="dept.id">{{
              dept.deptName
            }}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item label="考核日期">
          <a-date-picker
            style="width: 100%"
            v-decorator="['eventInspectDate', { rules: [{ required: true, message: '请选择' }] }]"
            :format="dateFormat"
            @change="handleInspectionDateChange"
            :disabled="type == 2 || type === 3"
          />
        </a-form-item>

        <a-form-item label="被考核支部">
          <a-select
            v-decorator="['inspectBranch', { rules: [{ required: true, message: '请选择' }] }]"
            placeholder="请选择被考核支部"
            @change="handleInspectBranchChange"
            :disabled="type == 2 || type === 3"
          >
            <a-select-option :value="item.id" v-for="item in allBranch" :key="item.id">{{
              item.branchName
            }}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item label="被考核部门">
          <a-select
            mode="multiple"
            v-decorator="['inspectDeptList', { rules: [{ required: true, message: '请选择' }] }]"
            placeholder="请选择考核部门"
            :disabled="type == 2 || type === 3"
          >
            <a-select-option :value="dept.id" v-for="dept in allInspectDept" :key="dept.id">{{
              dept.deptName
            }}</a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item label="发生日期">
          <a-date-picker
            style="width: 100%"
            v-decorator="['eventCreateDate', { rules: [{ required: true, message: '请选择' }] }]"
            @change="handleEventCreateDateChange"
            :disabled="type == 2 || type === 3"
          />
        </a-form-item>

        <a-form-item label="考核分">
          <a-input
            v-decorator="[
              'inspectScore',
              { rules: [{ required: true, message: '请输入考核分数' }] },
            ]"
            placeholder="请输入"
            :disabled="type === 3"
          />
        </a-form-item>

        <a-form-item label="考核条例">
          <a-select
            v-decorator="['regulationId', { rules: [{ required: true, message: '请选择' }] }]"
            placeholder="请选择考核条例"
            @change="handleRegulationChange"
            :disabled="type == 2 || type === 3"
          >
            <a-select-option
              :value="regulation.id"
              v-for="regulation in allRegulation"
              :key="regulation.id"
            >
              {{ regulation.regulationName }}
            </a-select-option>
          </a-select>
        </a-form-item>

        <a-form-item label="条例内容">
          <a-input v-decorator="['regulationContent', { rules: [] }]" disabled></a-input>
        </a-form-item>

        <a-form-item label="最低分">
          <a-input v-decorator="['lowestScore', { rules: [] }]" disabled></a-input>
        </a-form-item>

        <a-form-item label="最高分">
          <a-input v-decorator="['highestScore', { rules: [] }]" disabled></a-input>
        </a-form-item>

        <a-form-item label="考核类别">
          <a-input v-decorator="['inspectionType', { rules: [] }]" disabled></a-input>
        </a-form-item>

        <a-form-item label="备注">
          <a-input :disabled="type === 3" v-decorator="['remark', { rules: [] }]" placeholder="请输入" />
        </a-form-item>

        <a-form-item
          style="width: 800px"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 20 }"
          label="事件内容"
        >
          <a-textarea
            v-decorator="['eventContent', { rules: [] }]"
            placeholder="请输入"
            :rows="3"
            :disabled="type === 3"
          />
        </a-form-item>

        <a-form-item
          style="width: 800px"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 20 }"
          label="考核说明"
          
        >
          <a-textarea :disabled="type === 3" v-decorator="['inspectDesc', { rules: [] }]" placeholder="请输入" :rows="3" />
        </a-form-item>
      </a-form>
    </a-modal>

    <!-- 整改弹窗 -->
    <a-modal
      width="900px"
      title="整改"
      :visible="rectifMod"
      :confirm-loading="rectifLoading"
      @ok="rectifOk"
      @cancel="rectifCancel"
    >
      <a-form v-bind="formItemLayout" :form="rectifForm">
        <a-form-item
          label="整改内容"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 16 }"
          style="width: 100%"
        >
          <a-textarea
            v-decorator="['correctContent', { rules: [{ required: true }] }]"
            placeholder="请输入"
            :rows="3"
          />
        </a-form-item>
        <a-form-item
          label="整改日期"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 16 }"
          style="width: 100%"
        >
          <a-date-picker
            v-decorator="['correctDate', { rules: [{ required: true, message: '请选择' }] }]"
          />
        </a-form-item>
        <a-form-item
          label="填报人"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 16 }"
          style="width: 100%"
        >
          <a-input
            v-decorator="['reportUserName', { rules: [{ required: true, message: '填报人' }] }]"
          />
        </a-form-item>
        <a-form-item
          label="填报日期"
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 16 }"
          style="width: 100%"
        >
          <a-date-picker
            v-decorator="['reportDate', { rules: [{ required: true, message: '请选择' }] }]"
          />
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 4 }"
          :wrapperCol="{ span: 16 }"
          label="是否整改"
          style="width: 100%"
        >
          <a-select
            v-decorator="[
              'isCorrect',
              {
                initialValue: '0',
                rules: [{ required: true, message: '' }],
              },
            ]"
          >
            <a-select-option value="0" key="0">否</a-select-option>
            <a-select-option value="1" key="1">是</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-modal>
  </a-card>
</template>

<script>
import { basicService, inspectionService } from '@/services';
import { BASE } from '@/services/api';

const originColumns = [
  {
    title: '序号',
    key: 'id',
    customRender: (text, record, index) => `${index + 1}`,
    align: 'center',
    width: 80,
  },
  {
    title: '被考核支部',
    key: 'inspectBranchName',
    dataIndex: 'inspectBranchName',
    align: 'center',
    sorter: true,
    width: 150,
  },
  {
    title: '发生日期',
    key: 'eventCreateDate',
    dataIndex: 'eventCreateDate',
    align: 'center',
    sorter: true,
    width: 150,
  },
  {
    title: '事件内容',
    key: 'eventContent',
    dataIndex: 'eventContent',
    scopedSlots: { customRender: 'eventContent' },
    align: 'center',
    width: 350,
  },
  {
    title: '考核说明',
    key: 'inspectDesc',
    dataIndex: 'inspectDesc',
    align: 'center',
    ellipsis: true,
    width: 150,
  },
  {
    title: '考核分',
    key: 'inspectScore',
    dataIndex: 'inspectScore',
    align: 'center',
    sorter: true,
    width: 100,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    align: 'center',
    width: 100,
  },
  {
    title: '考核条例',
    key: 'regulationNo',
    dataIndex: 'regulationNo',
    align: 'center',
    sorter: true,
    width: 120,
  },
  {
    title: '条例内容',
    key: 'regulationContent',
    dataIndex: 'regulationContent',
    scopedSlots: { customRender: 'regulationContent' },
    align: 'center',
    width: 300,
  },
  {
    title: '考核类别',
    key: 'inspectionType',
    dataIndex: 'inspectionType',
    align: 'center',
    sorter: true,
    width: 120,
  },
  {
    title: '考核部门',
    key: 'executeDeptName',
    dataIndex: 'executeDeptName',
    align: 'center',
    sorter: true,
    width: 120,
  },
  {
    title: '考核日期',
    key: 'eventInspectDate',
    dataIndex: 'eventInspectDate',
    align: 'center',
    sorter: true,
    width: 150,
  },
  {
    title: '是否已审批',
    key: 'approveStatus',
    dataIndex: 'approveStatus',
    scopedSlots: { customRender: 'approveStatus' },
    align: 'center',
    width: 120,
  },
  {
    title: '是否整改',
    key: 'isCorrect',
    dataIndex: 'isCorrect',
    scopedSlots: { customRender: 'status' },
    align: 'center',
    sorter: true,
    width: 120,
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    width: 160,
    fixed: 'right',
  },
];

const formItemLayout = {
  labelCol: { span: 8 },
  wrapperCol: { span: 16 },
};

import moment from 'moment';
import 'moment/locale/zh-cn';
moment.locale('zh-cn');

export default {
  name: 'inspectionEvent',

  data() {
    return {
      advanced: true,
      formItemLayout,
      originColumns,
      columns: [],
      columnsOptions: [], // 可选的表格列
      colList: [], // 表格列筛选
      // 搜索表单
      searchForm: {
        range: [],
        inspectionType: null,
        executeDept: null,
        regulationNo: null,
        inspectBranch: null,
        eventContent: '',
        inspectScore: null,
        isCorrect: null,
        sortName: '',
        sortOrder: null,
        regulationList: [], // 该部门可选考核条例
      },
      dataSource: [],
      pagination: {
        showSizeChanger: true,
        pageSizeOptions: ['10', '50', '100', '200'],
        showQuickJumper: true,
        showTotal: total => `共${total}条`,
        current: 1,
        pageSize: 10,
        total: 0,
      },
      loading: false,
      visible: false,
      form: this.$form.createForm(this, { name: 'add_event' }),
      confirmLoading: false,
      dateFormat: 'YYYY-MM-DD',
      allBranch: [],
      allDept: [],
      allInspectDept: [],
      allRegulation: [],
      type: 1,
      changeID: '',
      rectifMod: false,
      rectifForm: this.$form.createForm(this, { name: 'rectifForm' }),
      rectifLoading: false,
      rectifID: '',
      rowSelection: {
        selectedRowKeys: [],
        onChange: selectedRowKeys => (this.rowSelection.selectedRowKeys = selectedRowKeys),
      },
      dictList: [],
    };
  },

  computed: {
    inspectionTypeOptions() {
      return this.dictList['inspectionType'] || [];
    },
  },

  created() {
    this.getDict();
    this.getAllBranch();
    this.getAllDept();
    this.getDataSource();

    // 初始化表格列
    this.columns = this.originColumns;
    this.columnsOptions = this.originColumns.map(item => {
      return {
        label: item.title,
        value: item.key,
      };
    });
    this.colList = originColumns.map(c => c.key);
  },

  methods: {
    // 查询
    handleSearch() {
      this.getDataSource();
    },

    // 重置
    handleReset() {
      this.searchForm = {
        range: [],
        inspectionType: null,
        executeDept: null,
        regulationNo: null,
        inspectBranch: null,
        eventContent: '',
        inspectScore: null,
        isCorrect: null,
        sortName: '',
        sortOrder: null,
        regulationList: [],
      };
    },

    // 查询表单选择部门
    handleSearchFormExecuteDeptChange(value) {
      console.log(value);
      inspectionService.getAllRegulation({ departmentId: value }).then(res => {
        if (res.code === '200') {
          this.searchForm.regulationList = res.data.items;
        }
      });
    },

    // 分页切换
    handleTableChange(pagination, filters, sorter) {
      console.log({ pagination, filters, sorter });
      this.pagination = { ...this.pagination, ...pagination };
      if (sorter.order) {
        this.searchForm.sortName = sorter.columnKey;
        this.searchForm.sortOrder = sorter.order === 'ascend' ? 1 : -1;
      } else {
        this.searchForm.sortName = '';
        this.searchForm.sortOrder = null;
      }
      this.getDataSource();
    },

    // 新增考核事件
    handleAddEvent() {
      this.visible = true;
      this.type = 1;
      this.changeID = '';
    },

    // 修改
    handleEdit(item) {
      this.visible = true;
      this.type = 2;
      this.changeID = item.id;
      inspectionService.getEventDetail({ id: item.id }).then(res => {
        console.log(res.data);
        setTimeout(() => {
          this.getAllRegulation({ departmentId: res.data.executeDept });
          this.handleRegulationChange(res.data.regulationId);
          this.handleInspectBranchChange(res.data.inspectBranch);
          this.form.setFieldsValue({ ...res.data });
        }, 100);
      });
    },

    // 批量导出event
    handleExport() {
      const token = localStorage.getItem('token');
      const url = `${BASE}/event/export?token=${token}`;
      const link = document.createElement('a');
      link.target = '_blank';
      link.href = url;
      link.click();
    },

    // 表格列筛选
    handleColChange(val) {
      console.log(val);
      this.columns = this.originColumns.filter(col => {
        return val.includes(col.key);
      });
    },

    handleDelete(item) {
      inspectionService.delEvent({ id: item.id }).then(() => {
        this.$message.success('操作成功');
        this.getDataSource();
      });
    },

    /* form 表单相关 */
    // 选择考核部门
    handleExecuteDeptChange(value) {
      console.log('考核部门id', value);
      this.form.setFieldsValue({
        executeDept: value,
      });
      this.getAllRegulation({ departmentId: value });
    },

    // 选择考核日期
    handleInspectionDateChange(value) {
      console.log('考核日期', value);
      this.form.setFieldsValue({
        eventInspectDate: value,
      });
    },

    // 选择发生日期
    handleEventCreateDateChange(value) {
      console.log('发生日期', value);
      this.form.setFieldsValue({
        eventCreateDate: value,
      });
    },

    // 选择被考核支部
    handleInspectBranchChange(value, option) {
      console.log(value, option);
      const branch = this.allBranch.find(item => item.id === value);
      if (branch && branch.departments.length) {
        this.allInspectDept = branch.departments;
      }
    },

    // 选择考核条例
    handleRegulationChange(value) {
      console.log('考核条例', value);
      const regulation = this.allRegulation.find(item => item.id === value);
      console.log(regulation, '----');
      const { regulationContent, lowestScore, highestScore, inspectionType } = regulation;
      this.form.setFieldsValue({
        regulationId: value,
        regulationContent: regulationContent,
        lowestScore,
        highestScore,
        inspectionType,
      });
    },

    // 新建考核事件确认
    handleOk() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true;
          console.log('Received values of form: ', values);
          values.eventInspectDate = moment(values.eventInspectDate).format('YYYY-MM-DD HH:mm:ss');
          values.eventCreateDate = moment(values.eventCreateDate).format('YYYY-MM-DD HH:mm:ss');
          if (this.type === 2) {
            inspectionService
              .eventUpdate({ ...values, id: this.changeID })
              .then(res => {
                console.log(res);
                if (res.code === '200') {
                  this.$message.success('操作成功');
                  this.visible = false;
                  this.form.resetFields();
                  this.getDataSource();
                }
              })
              .catch(e => {
                this.$message.error(e);
              })
              .finally(() => {
                this.confirmLoading = false;
              });
          } else {
            inspectionService
              .addEvent(values)
              .then(res => {
                console.log(res);
                if (res.code === '200') {
                  this.$message.success('操作成功');
                  this.visible = false;
                  this.form.resetFields();
                  this.getDataSource();
                }
              })
              .catch(e => {
                this.$message.error(e);
              })
              .finally(() => {
                this.confirmLoading = false;
              });
          }
        }
      });
    },

    // 取消新建考核事件
    handleCancel() {
      this.visible = false;
      this.form.resetFields();
      this.changeID = '';
    },

    // 审批
    handleApprove(item) {
      inspectionService.approve({ id: item.id }).then(res => {
        if (res.code == '200') {
          this.$message.success('审批成功');
          this.getDataSource();
        }
      })
    },

    //整改
    rectification(item) {
      this.changeID = item.id;
      inspectionService.rectifiGet({ eventId: item.id, id: this.rectifID }).then(res => {
        console.log(res.code == '200');
        if (res.code == '200') {
          this.rectifMod = true;
          res.data && res.data.id && (this.rectifID = res.data.id);
          console.log(res.data);
          setTimeout(() => {
            this.rectifForm.setFieldsValue({
              ...res.data,
              isCorrect: JSON.stringify(res.data.isCorrect),
            });
          }, 100);
        }
      });
    },
  
    rectifOk() {
      this.rectifForm.validateFields((err, values) => {
        if (!err) {
          this.confirmLoading = true;
          console.log('Received values of form: ', values);
          inspectionService
            .rectification({
              ...values,
              eventId: this.changeID,
              id: this.rectifID,
            })
            .then(res => {
              console.log(res);
              if (res.code == '200') {
                this.$message.success('操作成功');
                this.rectifMod = false;
                this.rectifID = '';
                this.rectifForm.resetFields();
                this.getDataSource();
              }
            })
            .catch(e => {
              this.$message.error(e);
            })
            .finally(() => {
              this.confirmLoading = false;
            });
        }
      });
    },
    rectifCancel() {
      this.rectifMod = false;
      this.rectifForm.resetFields();
      this.changeID = '';
      this.rectifID = '';
    },
    // 批量删除
    handleDelAll() {
      console.log('批量删除', this.rowSelection.selectedRowKeys);
    },

    // 添加表格事件
    customRow(record) {
      const that = this;
      return {
        on: {
          dblclick: e => {
            console.log(record, e);
            that.visible = true;
            that.type = 3;
            inspectionService.getEventDetail({ id: record.id }).then(res => {
              setTimeout(() => {
                that.getAllRegulation({ departmentId: res.data.executeDept });
                that.handleRegulationChange(res.data.regulationId);
                that.handleInspectBranchChange(res.data.inspectBranch);
                that.form.setFieldsValue({ ...res.data });
              }, 100);
            });
          },
        },
      };
    },

    // 获取字典
    getDict() {
      const typeList = ['inspectionType'];
      basicService.getDictByFlag({ typeList }).then(res => {
        if (res.code === '200') {
          this.dictList = res.data.typeMap;
        }
      });
    },

    // 获取所有支部
    getAllBranch() {
      inspectionService.getAllBranch({ needDetail: true }).then(res => {
        if (res.code === '200') {
          this.allBranch = res.data.items;
        }
      });
    },

    // 获取所有部门
    getAllDept() {
      inspectionService.getAllDept().then(res => {
        if (res.code === '200') {
          this.allDept = res.data.items;
        }
      });
    },

    // 获取所有条例
    getAllRegulation(params) {
      inspectionService.getAllRegulation(params).then(res => {
        if (res.code === '200') {
          this.allRegulation = res.data.items;
        }
      });
    },

    // 获取数据
    getDataSource() {
      this.loading = true;

      const params = {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        ...this.searchForm,
      };

      if (this.searchForm.range.length) {
        params.eventInspectDateStart = moment(this.searchForm.range[0]).format(
          'YYYY-MM-DD HH:mm:ss'
        );
        params.eventInspectDateEnd = moment(this.searchForm.range[1]).format('YYYY-MM-DD HH:mm:ss');
      }

      inspectionService.getEventList(params).then(res => {
        console.log(res);
        this.dataSource = res.data.content;
        this.pagination.total = res.data.totalElements;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="less" scoped>
@import './index.less';
</style>
